import {getGoodDetail} from "http"
export default {
    state:{
        goodDetail:{}
    },
    getters:{
        categoryView(state){
            const categoryView = state.goodDetail.categoryView;
            return categoryView ? categoryView : {}
        },
        skuInfo(state){
            const skuInfo = state.goodDetail.skuInfo;
            return skuInfo ? skuInfo : {}
        },
        updatePrice(state,getters){
            return `¥${getters.skuInfo.price}`
        },
        spuSaleAttrList(state) {
            const spuSaleAttrList = state.goodDetail.spuSaleAttrList;
            return spuSaleAttrList ? spuSaleAttrList : []
        },
        skuImageList(state,getters){
            const skuInfo = getters.skuInfo
            const skuImageList = skuInfo.skuImageList;
            return skuImageList ? skuImageList : []
        }
    },
    mutations:{
        getGoodDetail(state,goodDetail){
            state.goodDetail = goodDetail
        },
        activeDD(state,{wrapIndex,innerIndex}){
            state.goodDetail.spuSaleAttrList[wrapIndex].spuSaleAttrValueList.forEach((item)=>{
                item.isChecked = "0"
            })
            state.goodDetail.spuSaleAttrList[wrapIndex].spuSaleAttrValueList[innerIndex].isChecked="1"
        }
    },
    actions:{
        async getGoodDetail({commit},skuid){
            const {code,data} = await getGoodDetail(skuid);
            if(code === 200){
                commit("getGoodDetail",data)
            }
        },
        //点击分类功能
        async activeDD({commit},{wrapIndex,innerIndex}){
            commit("activeDD",{wrapIndex,innerIndex})
        }
    }
}
